home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / gamma.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  2KB  |  90 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  GAMMA.H - Gamma Correction Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #ifndef _GAMMA_H
  39. #define _GAMMA_H
  40.  
  41. #include "color.h"
  42.  
  43. static const int G_Domain = 256;        // Input domain
  44. static const int G_Range = 256;         // Output range
  45.  
  46. class Gamma     // Gamma correction
  47. {
  48.   private:
  49.     // Gamma correction lookup table
  50.     static BYTE GammaTable[256];
  51.  
  52.     double g_value;     // Gamma value
  53.  
  54.     void InitTable()
  55.     {
  56.       int i;    // Loop index
  57.  
  58.       // Calculate gamma correction lookup table entries
  59.       for (i = 0; i < G_Domain; i++)
  60.         GammaTable[i] = (BYTE) ((double) G_Range *
  61.             pow((double) i / (double) G_Domain, 1.0 /
  62.             g_value));
  63.     }
  64.  
  65.   public:
  66.     Gamma( double g = 2.2 )
  67.     {
  68.       g_value = g;
  69.       InitTable();
  70.     }
  71.  
  72.     double GetGamma() { return g_value; }
  73.  
  74.     void Correct( ColorRGB &c )
  75.     {
  76.       c.SetRed(GammaTable[(UBYTE)c.GetRed()]);
  77.       c.SetGreen(GammaTable[(UBYTE)c.GetGreen()]);
  78.       c.SetBlue(GammaTable[(UBYTE)c.GetBlue()]);
  79.     }
  80.  
  81.     void SetGamma( double g )
  82.     {
  83.       g_value = g;
  84.       InitTable();
  85.     }
  86. };
  87.  
  88. #endif
  89.  
  90.